#include <bits/stdc++.h>
using namespace std;
class CSV
{
public:
    CSV(const char *filename)
    {
        InputData(filename);
    };

    ~CSV(){

    };

private:
    vector<vector<string>> data;
    int rowNum = 0;

    void InputData(const char *filename)
    {
        ifstream in(filename);
        if (!in.is_open())
        {
            cout << "open error";
            exit(0);
        }

        string line;
        while (getline(in, line))
        {
            vector<string> row;
            string cell;
            stringstream ss(line);
            while (getline(ss, cell, ','))
            {
                row.push_back(cell);
            }
            data.push_back(row);
            rowNum++;
        }
        in.close();
    };
//22001010118 张镈镟
public:
    vector<string> getRow(int row) // 返回某行的数据
    {
        return data[row];
    }
    int getRowNum() // 返回行数
    {
        return rowNum;
    }
    int getdataNum(int row) // 返回某行的数据个数
    {
        return data[row].size();
    }
    string getdata(int row, int col) // 返回某行某列的数据
    {
        return data[row][col];
    }
    static void row_printf(vector<string> a)
    {
        for (int i = 0; i < a.size(); i++)
            cout << a[i] << ' ';
        cout << endl;
    }
};
//22001010118 张镈镟
void solve(CSV &ori, CSV &ch)
{
    int cnt = 0;
    for (int i = 0; i < ori.getRowNum(); i++)
    {
        if (ch.getRow(i) == ori.getRow(i + cnt))
            continue;

        if (ch.getdata(i, 0) == ch.getdata(i - 1, 0))
        {
            printf("第%d行 数据重复,重复的数据是：", i + 1);
            CSV::row_printf(ch.getRow(i));
            cnt--;
        }
        else if (ch.getdata(i, 0) == ori.getdata(i + 1 + cnt, 0))
        {
            printf("第%d行 数据缺失,缺失的数据是：", i + 1);
            CSV::row_printf(ori.getRow(i + cnt));
            cnt++;
        }
        else if (ch.getdata(i, 1) != ori.getdata(i + cnt, 1))
        {
            printf("第%d行 学号错误\n", i + 1);
            cout << "错误的学号是: " << ch.getdata(i, 1) << endl;
            cout << "正确的学号是: " << ori.getdata(i + cnt, 1) << endl;
        }
        else if (ch.getdata(i, 2) != ori.getdata(i + cnt, 2))
        {
            printf("第%d行 姓名错误\n", i + 1);
            cout << "错误的姓名是：" << ch.getdata(i, 2) << endl;
            cout << "正确的姓名是：" << ori.getdata(i + cnt, 2) << endl;
        }
        else if (ch.getdata(i, 3) != ori.getdata(i + cnt, 3))
        {
            printf("第%d行 班级错误\n", i + 1);
            cout << "错误的班级是：" << ch.getdata(i, 3) << endl;
            cout << "正确的班级是：" << ori.getdata(i + cnt, 3) << endl;
        }

        cout << endl;
    }
}
//22001010118 张镈镟
int main()
{
    const char *checked = "D:\\csv\\data_for_check.csv";
    const char *original = "D:\\csv\\original_data.csv";
    CSV ori(original);
    CSV ch(checked);

    solve(ori, ch);
    return 0;
}